package ru.dc.gui.swing;

import ru.dc.gui.swing.util.ClosableTabComponent;

import javax.swing.*;
import java.awt.*;

/**
 * <pre>
 * User: Penkov Vladimir
 * Date: 01.11.2010
 * Time: 11:47:07
 * </pre>
 */
public class Tab extends JPanel {

    private ClosableTabComponent tabComponent;
    private JTabbedPane tabbedPane;

    public void setTabComponent(ClosableTabComponent tabComponent) {
        this.tabComponent = tabComponent;
    }

    public void setTabbedPane(JTabbedPane tabbedPane) {
        this.tabbedPane = tabbedPane;
    }

    public boolean isSelected() {
        return tabbedPane.getSelectedComponent().equals(this);
    }

    public void init(){}

    public void close() {
    }

    public void onSelect() {
        tabComponent.getCaption().setForeground(Color.BLACK);
    }

    public Icon getIcon() {
        return tabComponent.getCaption().getIcon();
    }

    public void setIcon(Icon icon) {
        tabComponent.setIcon(icon);
    }

    public String getTitle() {
        return tabComponent.getCaption().getText();
    }

    public void setTitle(String title) {
        tabComponent.setTitle(title);
    }

    public void alert() {
        if (!isSelected()) {
            tabComponent.getCaption().setForeground(Color.RED);
        }
    }
}
